<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

require_once ADMIN.DS."/head.php";
?>
<h1>Смайлы</h1><?php
	if ($route->GET("add") == "success"){
		echo "<p class='success'><br />Успешно добавлено</p>";
	} elseif ($route->GET("add") == "fail") {
		echo "<p class='fail'><br />Не удалось добавить</p>";
	}
	if ($route->GET("edit") == "success"){
		echo "<p class='success'><br />Успешно обновлено</p>";
	} elseif ($route->GET("edit") == "fail") {
		echo "<p class='fail'><br />Не удалось обновить</p>";
	}
?><br />
<table cellpadding='0' cellspacing='0' class='list'>
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='100px'>Обозначение</td>
		<td width='150px'>Значение</td>
		<td width='200px' class='actions'>Действия</td>
	</tr><?php
		$smiles = $db->getTable("select * from `smiles` order by `smile_id`");
		foreach ($smiles as $smile)
		{
			echo "<tr><td>$smile[smile_id]</td>";
			echo "<td>";
				echo "<form id='form_$smile[smile_id]' method='post' action='/admin/smiles/edit'>";
					echo "<input type='hidden' name='smile_id' value='$smile[smile_id]' />";
					echo "<input type='text' style='width:50px' name='symbol' value='$smile[symbol]' />";
					echo "<input type='hidden' id='type_$smile[smile_id]' name='type' value='$smile[type]' />";
				echo "</form>";
			echo "</td>";
			echo "<td>";
				$smiles_arr = array(array("type"=>"good","text"=>"Понравился"),array("type"=>"neural","text"=>"Нейтрально"),array("type"=>"bad","text"=>"Не понравился"));
				echo "<select onchange=\"$('#type_$smile[smile_id]').val($(this).val())\">";
					echo select_create($smiles_arr,"type","text",$smile['type']);
				echo "</select>";
			echo "</td>";
			echo "<td class='actions'><a href='javascript:void(0)' onclick=\"$('#form_$smile[smile_id]').submit()\" class='edit'>Редактировать</a> | <a href='/admin/smiles/delete/$smile[smile_id]' class='delete'>Удалить</a></td></tr>";
		}
	?>
	<tr>
		<td></td>
		<td colspan='2'>
			<form id="new_form" action='/admin/smiles/add' method='post'>
				<input type='text' name='symbol' style='width:50px' />
				<select name='type' style="width:150px;margin-left:42px">
					<?php echo select_create($smiles_arr,"type","text"); ?>
				</select>
			</form>
		</td>
		<td><a href='javascript:void(0)' onclick="$('#new_form').submit()" style="margin-left: 25px">Добавить</a></td>
	</tr>
</table>

<?php require_once ADMIN.DS."/footer.php"; ?>